<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="用户授权" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<style type="text/css">
<!--
.topbar {font-size:12px;}
	.eNav li{ background-image:url(/images/nav.gif); background-repeat:no-repeat; width:97px; height:40px; float:left; text-align:center;}
	.eNav li.on{ background-image:url(/images/navOn.gif); background-repeat:no-repeat}
	.eNav li a{ display:block;width:97px; height:36px; line-height:36px; color:#898989; font-weight:bold; text-decoration:none;}
	.eNav li a:hover{text-decoration:none;}
	.eNav li.on a{ color:#515151}
	.eNav li.on a:visited{ color:#515151}
	.eNav li a:visited{ color:#898989}
.grey {color:grey}
-->
</style>
<script language="javascript">
	function doSave(){
		document.getElementById("buttonDiv").style.display="none";
		document.getElementById("waitDiv").style.display="";
		frm.submit();
	}
	function doCancel(){
		parent.ClosePop();
	}
	function doTallySetChange(obj,f){
		var objs=document.getElementsByName("ts_privilege");
		var str="";
		for(i=0;i<objs.length;i++){
			if(objs[i].checked){
				str=str+";"+objs[i].value;
			}
		}
		if(str!=""){
			str=str+";";
		}
		f.ts_privilege_str.value=str;
	}
	function doWorkCenterChange(obj,f){
		var objs=document.getElementsByName("wc_privilege");
		var str="";
		for(i=0;i<objs.length;i++){
			if(objs[i].checked){
				str=str+";"+objs[i].value;
			}
		}
		if(str!=""){
			str=str+";";
		}
		f.wc_privilege_str.value=str;
	}
	function doBaChange(obj,f){
		var objs=document.getElementsByName("ba_privilege");
		var str="";
		for(i=0;i<objs.length;i++){
			if(objs[i].checked){
				str=str+";"+objs[i].value;
			}
		}
		if(str!=""){
			str=str+";";
		}
		f.ba_privilege_str.value=str;
	}
	function doChange(obj,f){
		var objs=document.getElementsByName("privilege");
		var parentChecked=false;
		var parent=null;
		if(obj.checked){
			parentChecked=true;
		}
		if(objs.length!=null){
			for(i=0;i<objs.length;i++){
				if(objs[i].getAttribute("parentIdStr")!=null && objs[i].getAttribute("parentIdStr").indexOf(";"+obj.value+";")!=-1){
					objs[i].checked=obj.checked;
				}
				if(obj.getAttribute("parentId")!=null && obj.getAttribute("parentId")!='0'){
					if(objs[i].getAttribute("parentId")==obj.getAttribute("parentId") && objs[i].checked){
						parentChecked=true;
					}
					if(obj.getAttribute("parentId")==objs[i].value){
						parent=objs[i];
					}
				}
			}
			if(parent!=null){
				parent.checked=parentChecked;
			}
			
			var str="";
			for(i=0;i<objs.length;i++){
				if(objs[i].checked){
					str=str+";"+objs[i].getAttribute("privilegeCode");
				}
			}
			if(str!=""){
				str=str+";";
			}
			f.privilege_str.value=str;
		}
	}
	function doInit(){
		showFormErrorMsg();
		resizePopwin();
	}
	function doShow(index,total){
		for(var i=0;i<total;i++){
			if(document.getElementById("liTop"+i)){
				document.getElementById("liTop"+i).className="";
			}
			if(document.getElementById("contDiv"+i)){
				document.getElementById("contDiv"+i).style.display="none";
			}
		}
		document.getElementById("liTop"+index).className="on";
		document.getElementById("contDiv"+index).style.display="";
	}
</script>
<script language="javascript">
	var formErrorIndex=0;
	var formErrorMsg="";
	var formErrorObjId="";
	function setFormErrorMsg(msg,index,objId){
		if(formErrorIndex==0 || formErrorIndex>index){
			if(msg!=null && msg!=""){
				formErrorIndex=index;
				formErrorMsg=msg;
				formErrorObjId=objId;
			}
		}
	}
	function showFormErrorMsg(){
		if(formErrorIndex!=0){
			document.getElementById("errorMsgTr").style.display="";
			document.getElementById("errorMsgDiv").innerHTML=formErrorMsg;
			if(formErrorObjId!=null && formErrorObjId!=""){
				document.getElementById(formErrorObjId).focus();
			}
		}
	}
	function goNextInput(objId){
		var obj=null;
		if(objId!=null && objId!=''){
			obj=document.getElementById(objId);
		}
		if(window.event.keyCode==13){
			if(obj!=null){
				obj.focus();
			}else if(window.doSave){
				doSave();
			}
		}
	}
</script>
</head>
<body onload="doInit();"  class="sheet modal-dialog"style=" padding-top:10px;">
<div class="sheet-main" id="bodyDiv" style="width:860px;">
	<form name="frm" method="post" action="UserPrivilegeSet.ihtm">
	  <div class="sheet-list" style="width:100%">
		    <div class="modal-main search-business">
		    	<div style="width:100%;">
		    		<div class="blank24"></div>
					<ul class="eNav">
						<c:set var="tagTotal" value="${fn:length(grouList)+3}" />
						<li id='liTop0' class="topbar on" onClick="doShow(0,${tagTotal});"><a href="#">帐套</a></li>
						<c:if test="${enterpriseInfo.workCenter=='Y'}">
							<li id='liTop1' class="topbar" onClick="doShow(1,${tagTotal});"><a href="#">工作中心</a></li>
						</c:if>
						<c:if test="${enterpriseInfo.bankPr=='Y'}">
							<li id='liTop2' class="topbar" onClick="doShow(2,${tagTotal});"><a href="#">银行账户</a></li>
						</c:if>
						<c:forEach var="item" items="${grouList}" varStatus="i">
							<li id='liTop${i.index+3}' class="topbar" onClick="doShow(${i.index+3},${tagTotal});"><a href="#">${item.privilegeName}</a></li>
						</c:forEach>
					</ul>
		    		
		    		<div id="contDiv0">
						<table width="100%" border="0" cellspacing="0" cellpadding="1" align="center" class="table-list">
					        <tr >
					        	<td width="200px" style="vertical-align:top;padding-top:10px">
					        		帐套授权<span class="fei">（必须先授权给用户一个账套的权限，否则登录系统后看不到任何业务数据）</span>
					        	</td>
					        	<td>
					        		<table width="100%">
					        			<c:forEach var="cItem" items="${tallySetList}">
					        			<tr>
					        				<td height="24px" style="text-align:left">
					        					<c:set var="itemCode" value=";${cItem.id};" />
					        					<input <c:if test="${fn:indexOf(ub.tsPrivs,itemCode)!=-1}">checked</c:if> type="checkbox" onClick="doTallySetChange(this,frm);" name="ts_privilege" value="${cItem.id}">
					        					${cItem.title}
					        				</td>
					        			</tr>
					        			</c:forEach>
					        		</table>
					        	</td>
					        </tr>
						</table>
		    		</div>
					
					<c:if test="${enterpriseInfo.workCenter=='Y'}">
						<div id="contDiv1" style="display:none">
							<table width="100%" border="0" cellspacing="0" cellpadding="1" align="center" class="table-list">
						        <tr >
						        	<td width="200px" style="vertical-align:top;padding-top:10px">
						        		工作中心授权
						        	</td>
						        	<td>
						        		<table width="100%">
						        			<c:forEach var="cItem" items="${workCenterList}">
						        			<tr>
						        				<td height="24px" style="text-align:left">
						        					<c:set var="itemCode" value=";${cItem.id};" />
						        					<input <c:if test="${fn:indexOf(ub.wcPrivs,itemCode)!=-1}">checked</c:if> type="checkbox" onClick="doWorkCenterChange(this,frm);" name="wc_privilege" value="${cItem.id}">
						        					${cItem.wcName}
						        				</td>
						        			</tr>
						        			</c:forEach>
						        		</table>
						        	</td>
						        </tr>
							</table>
			    		</div>
					</c:if>
					
					<c:if test="${enterpriseInfo.bankPr=='Y'}">
						<div id="contDiv2" style="display:none">
							<table width="100%" border="0" cellspacing="0" cellpadding="1" align="center" class="table-list">
						        <tr >
						        	<td width="200px" style="vertical-align:top;padding-top:10px">
						        		银行账户授权
						        	</td>
						        	<td>
						        		<table width="100%">
						        			<c:forEach var="cItem" items="${baList}">
						        			<tr>
						        				<td height="24px" style="text-align:left">
						        					<c:set var="itemCode" value=";${cItem.id};" />
						        					<input <c:if test="${fn:indexOf(ub.baPrivs,itemCode)!=-1}">checked</c:if> type="checkbox" onClick="doBaChange(this,frm);" name="ba_privilege" value="${cItem.id}">
						        					${cItem.bankName}<c:if test="${cItem.accountName!=null && cItem.accountName!=''}">(${cItem.accountName})</c:if>
						        				</td>
						        			</tr>
						        			</c:forEach>
						        		</table>
						        	</td>
						        </tr>
							</table>
			    		</div>
					</c:if>
					
					<c:forEach var="pItem" items="${grouList}" varStatus="i">
						<div id="contDiv${i.index+3}" style="display:none">
							<table width="100%" border="0" cellspacing="0" cellpadding="1" align="center" class="table-list">
						        <tr >
						        	<td width="200px" style="vertical-align:top;padding-top:10px">
						        		<c:if test="${pItem.canSelect=='Y'}">
						        		<c:set var="itemCode" value=";${pItem.privilegeCode};" />
							        	<input <c:if test="${fn:indexOf(ub.privs,itemCode)!=-1}">checked</c:if> type="checkbox" onClick="doChange(this,frm);" name="privilege" value="${pItem.id}" privilegeCode="${pItem.privilegeCode}" parentId="${pItem.parentId}" parentIdStr="${pItem.parentIdStr}">
						        		</c:if>
						        		${pItem.privilegeName}<c:if test="${pItem.mark!=null && pItem.mark!=''}"><span class="fei">（${pItem.mark}）</span></c:if>
						        	</td>
						        	<td>
						        		<table width="100%">
						        			<c:forEach var="cItem" items="${privList}">
						        			<c:if test="${cItem.parentId==pItem.id}">
						        			<tr>
						        				<td height="24px" style="text-align:left">
						        					<c:set var="itemCode" value=";${cItem.privilegeCode};" />
						        					<input <c:if test="${fn:indexOf(ub.privs,itemCode)!=-1}">checked</c:if> type="checkbox" onClick="doChange(this,frm);" name="privilege" value="${cItem.id}" privilegeCode="${cItem.privilegeCode}" parentId="${cItem.parentId}" parentIdStr="${cItem.parentIdStr}">
						        					${cItem.privilegeName}<c:if test="${cItem.mark!=null && cItem.mark!=''}"><span class="fei">（${cItem.mark}）</span></c:if>
						        				</td>
						        			</tr>
						        			</c:if>
						        			</c:forEach>
						        		</table>
						        	</td>
						        </tr>
							</table>
			    		</div>
					</c:forEach>
					
				</div>							    	
		    </div>
	   </div>
		<div class="modal-buttom" id="buttonDiv">
			<input type="button" class="buttom" value=" 保 存 " onClick="doSave();">
			<input type="button" class="buttom" value=" 取 消 " onClick="doCancel();">
			<input type="hidden" name="privilege_str" id="privilege_str" value="${ub.privs}">
			<input type="hidden" name="ts_privilege_str" id="ts_privilege_str" value="${ub.tsPrivs}">
			<input type="hidden" name="wc_privilege_str" id="wc_privilege_str" value="${ub.wcPrivs}">
			<input type="hidden" name="ba_privilege_str" id="ba_privilege_str" value="${ub.baPrivs}">
		    <input type="hidden" name="user_id" id="user_id" value="${userId}">
		</div>	
		<div class="modal-buttom" id="waitDiv" style="display:none">
			<span style="color:#ffffff">请稍候...</span>
		</div>
	 </form> 
</div>
</body>
</html>